package com.macro.mall.review.controller;


import com.macro.mall.common.api.CommonPage;
import com.macro.mall.common.api.CommonResult;
import com.macro.mall.review.dto.ProductReviewsResponse;
import com.macro.mall.review.dto.ReviewViews;
import com.macro.mall.review.service.ReviewService;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/review")
public class ReviewController {
    @Autowired
    private ReviewService reviewService;

    @Operation(summary = "评论详情信息展示")
    @RequestMapping(value = "/getReviews", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<CommonPage<ProductReviewsResponse>> getReviews(
            @RequestParam Long id,
            @RequestParam(defaultValue = "1") int pageNum,
            @RequestParam(defaultValue = "10") int pageSize) {

        Page<ProductReviewsResponse> page = reviewService.getReviews(id, pageNum, pageSize);
        return CommonResult.success(CommonPage.restPage(page));
    }

    @Operation(summary = "添加评论")
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult add(@RequestBody ReviewViews reviewViews) {

      Integer i =  reviewService.add(reviewViews);
      return CommonResult.success(i);
    }

}
